#include <iostream>
#include <thread>
#include <mutex>
using namespace std;

int gCount = 0;
mutex mtx;

void threadFunc(void)
{
    for (size_t i = 0; i < 100000000; i++)
    {
        mtx.lock(); // 对共享资源加锁
        gCount++;
        mtx.unlock(); // 解锁
    }
}

int main()
{
    thread th1(threadFunc);
    thread th2(threadFunc);
    th1.join();
    th2.join();
    cout << "gCount = " << gCount << endl;
    return 0;
}